package com.tian.demo01.controller;

import com.tian.demo01.entity.Dept;
import com.tian.demo01.entity.Emp;
import com.tian.demo01.service.EmpService;
import com.tian.demo01.vo.EmpVo;
import com.tian.demo01.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/7/14/11:42
 */
@RestController
@Api(tags = "员工管理")
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    EmpService empService;

    @ApiOperation("查询员工信息")
    @PostMapping("/selectEmp")
    @ApiImplicitParam(name = "empVo" ,value = "查询员工信息的条件",required = true,dataType = "EmptVo")
    public R selectEmp(@RequestBody EmpVo empVo){
        return empService.selectAll(empVo);
    }

    @PostMapping("/insertEmp")
    @ApiOperation("添加员工信息")
    @ApiImplicitParam(name = "emp" ,value = "员工信息",required = true,dataType = "Emp")
    public R insertEmp(@RequestBody Emp emp){
        System.out.println("==================");
        System.out.println(emp);
        System.out.println("====================");
        return empService.insertEmp(emp);
    }

    @PutMapping("/updateEmp")
    @ApiOperation("修改员工信息")
    @ApiImplicitParam(name = "emp" ,value = "员工信息",required = true,dataType = "Emp")
    public R updateEmp(@RequestBody Emp emp){
        return empService.updateById(emp);
    }

    @DeleteMapping("/deletEmp/{id}")
    @ApiOperation("根据部门编号删除员工信息")
    @ApiImplicitParam(name = "id" ,value = "部门编号",required = true,dataType = "int")
    public R deleteById(@PathVariable int id){
        return empService.deleteById(id);
    }
}
